<?php

namespace app\admin\controller\uniwigs;

use app\common\controller\Backend;

/**
 * 规则管理
 *
 * @icon fa fa-circle-o
 */
class Cashcoderule extends Backend
{
    
    /**
     * CashCodeRule模型对象
     * @var \app\admin\model\CashCodeRule
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('CashCodeRule');
        $this->view->assign("categoryList", $this->model->getCategoryList());
        $this->view->assign("statusList", $this->model->getStatusList());
    }
    
     /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {	
	
			
			
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }
		
			
			//每个不同model 的 主键 不一致 默认为id 所以这里搜索要指定为 此model 的主键 id_code 
            list($where, $sort, $order, $offset, $limit) = $this->buildparams('id_code_rule');

			
            $total = $this->model
                    ->where($where)
                    ->order($sort, $order)
                    ->count();
			
			
		
			
            $list = $this->model
                    ->where($where)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();
		
			

            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

}
